package com.study.netty;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.channels.FileChannel;

public class FileChannelTest {
    public static void main(String[] args) {
        String file = FileChannelTest.class.getClassLoader().getResource("data.txt").getFile();
        String file1 = FileChannelTest.class.getClassLoader().getResource("dataTo.txt").getFile();
        System.out.println(file);
        System.out.println(file1);
        try(
                FileChannel fromChannel=new FileInputStream(file).getChannel();
                FileChannel toChannel=new FileOutputStream(file1).getChannel();
        ) {
            System.out.println(fromChannel.transferTo(0, fromChannel.size(), toChannel));
            toChannel.force(true);
        } catch (FileNotFoundException e) {
            throw new RuntimeException(e);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
}
